using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Data.Entity;


public partial class Doctors : System.Web.UI.Page
{
    private string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDoctorsGrid();
        }
    }
    private void BindDoctorsGrid()
    {
        using (var context = new HealthContext())
        {
            DoctorsGridView.DataSource = context.Doctors.ToList();
            DoctorsGridView.DataBind();
        }
    }

    protected void AddDoctorButton_Click(object sender, EventArgs e)
    {
        string name = NameTextBox.Text;
        string specialty = SpecialtyTextBox.Text;
        string licenseNumber = LicenseNumberTextBox.Text;
        string phoneNumber = PhoneNumberTextBox.Text;

        using (var context = new HealthContext())
        {
            var doctor = new Doctor
            {
                Name = name,
                Specialty = specialty,
                LicenseNumber = licenseNumber,
                PhoneNumber = phoneNumber,
                CreatedAt = DateTime.Now // 如果有 CreatedAt 字段
            };
            context.Doctors.Add(doctor);
            context.SaveChanges(); // 保存更改
        }

        NameTextBox.Text = "";
        SpecialtyTextBox.Text = "";
        LicenseNumberTextBox.Text = "";
        PhoneNumberTextBox.Text = "";
        BindDoctorsGrid();
    }

    protected void DoctorsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            // Edit functionality goes here
        }
    }
   
    // 假设 Doctor 是你数据库中 Doctors 表对应的模型类
    public class HealthContext : DbContext
    {
        public HealthContext() : base("name=DefaultConnection") // 确保这里的连接字符串名称正确
        {
        }

        public DbSet<Doctor> Doctors { get; set; } // Doctors 表
    }
    public class Doctor
    {
        public int DoctorID { get; set; }
        public string Name { get; set; }
        public string Specialty { get; set; }
        public string LicenseNumber { get; set; }
        public string PhoneNumber { get; set; }
        public DateTime CreatedAt { get; set; } // 如果有 CreatedAt 字段
    }

}